<template>
  <el-tabs v-model="tabPaneVal" type="border-card" @tab-click="handleClick">
    <el-tab-pane label="企业资料" name="ShipmentEdit">
      <ShipmentEdit v-if="isShipmentEditShow" ref="ShipmentEditRef" :parentData="parentData" />
    </el-tab-pane>
    <el-tab-pane label="开票信息管理" name="InvoiceMessage" v-if="!ctmsShow">
      <InvoiceMessage v-if="isInvoiceMessageShow"  ref="InvoiceMessageRef" :parentData="parentData" />
    </el-tab-pane>
    <el-tab-pane label="地址管理" name="CommonRouteInfo">
      <CommonRouteInfo v-if="isCommonRouteInfoShow" ref="CommonRouteInfoRef" :parentData="parentData" />
    </el-tab-pane>
    <el-tab-pane label="承运分组" name="VehicleTeam" v-if="!ctmsShow">
      <VehicleTeam v-if="isVehicleTeamShow" ref="VehicleTeamRef" :parentData="parentData" />
    </el-tab-pane>
    <el-tab-pane label="员工管理" name="ShipmentStaff">
      <ShipmentStaff v-if="isShipmentStaffShow" ref="ShipmentStaffRef" :parentData="parentData" />
    </el-tab-pane>
    <el-tab-pane label="上游客户管理" name="UpstreamCustomer">
      <UpstreamCustomer v-if="isUpstreamCustomerShow"  ref="UpstreamCustomerRef" :parentData="parentData" />
    </el-tab-pane>
    <el-tab-pane label="计价体系" name="PriceSystem" v-if="ctmsShow">
      <PriceSystem v-if="isPriceSystemShow"  ref="PriceSystemRef" :parentData="queryData" />
    </el-tab-pane>
    <el-tab-pane label="客户管理区域" name="CustomerManage" v-if="ctmsShow">
      <customerManage v-if="isCustomerManageShow"  ref="CustomerManageRef" :parentData="parentData" />
    </el-tab-pane>
    <el-tab-pane label="线路管理" name="LineManagement" v-if="ctmsShow">
      <lineManagement v-if="isLineManagementShow" ref="LineManagementRef" :parentData="parentData" />
    </el-tab-pane>
    <el-tab-pane label="合同管理" name="ShipmentContract" v-if="!ctmsShow">
      <ShipmentContract v-if="isShipmentContractShow" ref="ShipmentContractRef" :parentData="parentData" />
    </el-tab-pane>
  </el-tabs>
</template>

<script>
import ShipmentEdit from "./components/shipmentEdit.vue";
import InvoiceMessage from "./components/invoiceMessage/invoiceMessageList.vue";
import CommonRouteInfo from "./components/commonRouteInfo/commonRouteInfoList.vue";
import VehicleTeam from "./components/vehicleTeam/vehicleTeamList.vue";
import ShipmentStaff from "./components/shipmentStaff/shipmentStaffList.vue";
import UpstreamCustomer from "./components/upstreamCustomer/upstreamCustomerList.vue";
import PriceSystem from "@/views/basicInfo/priceSystem/priceSystem.vue";
import customerManage from "./components/customerManage/customerManage.vue";
import lineManagement from "./components/lineManagement/lineManagementList.vue";
import ShipmentContract from "./components/shipmentContract/shipmentContractList.vue";
import { SelectAddress } from "@/api/orderform";
import { getListDict, getGoodsTypeDict, getShipperList } from "@/api/shipment";
import { getRole } from '@/utils/getRole'
export default {
  name: "EditShipmentCompanyForm",
  components: {
    ShipmentEdit,
    InvoiceMessage,
    CommonRouteInfo,
    VehicleTeam,
    ShipmentStaff,
    UpstreamCustomer,
    PriceSystem,
    customerManage,
    lineManagement,
    ShipmentContract
  },
  data() {
    return {
      companyCode: '',
      parentData: {
        isCompany: true,
        areaOptions: [],
        goodsTypeList: [],
        typeOptions: [],
        vehicleDictList: [],
        bankOptions: [],
        receiverUserCodeOptions: [],
        upstreamCustomerList: []
      },
      queryData:{},
      tabPaneVal: "ShipmentEdit",
      isShipmentEditShow: true,
      isInvoiceMessageShow: false,
      isCommonRouteInfoShow: false,
      isVehicleTeamShow: false,
      isShipmentStaffShow: false,
      isUpstreamCustomerShow: false,
      isPriceSystemShow: false,
      isCustomerManageShow:false,
      isLineManagementShow:false,
      isShipmentContractShow:false,
      ctmsShow:false
    };
  },
  created() {
    this.ctmsShow = getRole();
    this.queryData=this.$route.query
    this.companyCode = this.$route.query.code ? this.$route.query.code : "";
    // 省市县
    SelectAddress().then(response => {
      this.parentData.areaOptions = response.data.records;
    });
    // 收票人选项
    getShipperList({ staffTypes: "1,4,6", companyCode: this.companyCode }).then(response => {
      this.parentData.receiverUserCodeOptions = response.data.records;
    });
    // 上游客户
    getShipperList({ staffType: '5', companyCode: this.companyCode }).then(response => {
      this.parentData.upstreamCustomerList = response.data.records
    });
    // 货物类型字典
    getGoodsTypeDict({ parentCode: "goodsBigType" }).then(response => {
      this.parentData.goodsTypeList = response.data.records;
    });
    // 开票方式、车型、开户银行
    getListDict({ types: "billingType, vehicleClassification, bank" }).then(
      response => {
        this.parentData.typeOptions = response.data.filter(
          item => item.type === "billingType"
        )[0]["dictList"];
        this.parentData.vehicleDictList = response.data.filter(
          item => item.type === "vehicleClassification"
        )[0]["dictList"];
        this.parentData.bankOptions = response.data.filter(
          item => item.type === "bank"
        )[0]["dictList"];
      }
    );
  },
  methods: {
    handleClick(tab, event) {
      this[`is${tab.name}Show`] = true;
      this.$nextTick(() => {
        this.$refs[`${tab.name}Ref`].findList() ;
      })
      // 重新获取 收票人
      if (tab.name === 'InvoiceMessage') {
        getShipperList({ staffTypes: "1,4,6", companyCode: this.companyCode }).then(response => {
          this.parentData.receiverUserCodeOptions = response.data.records;
        });
      }
      // 重新获取 上游客户
      if (tab.name === 'UpstreamCustomer') {
        getShipperList({ staffType: '5', companyCode: this.companyCode }).then(response => {
          this.parentData.upstreamCustomerList = response.data.records
        });
      }
    },

  }
};
</script>
